#include "stdafx.h"
#include "ServoPC.h"
#include "ServoMain.h"
#include "ServoPG.h"
#include "RobotDlg.h"
#include "SCServo/SCServo.h"
#include "SCServo/setup.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CServoPCApp

BEGIN_MESSAGE_MAP(CServoPCApp, CWinApp)
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CServoPCApp construction

CServoPCApp::CServoPCApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CServoPCApp object

CServoPCApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CServoPCApp initialization
BOOL CServoPCApp::InitInstance()
{
	AfxEnableControlContainer();

	CString setupPath;
	setupPath.LoadString(IDS_M_SETUP_PATH);
	CCriticalSection  *pCs = new CCriticalSection;
	CSetup *setup = new CSetup(setupPath);
	SCServo	*pServo =  new SCServo;
	CSCComm *pCom = new CSCComm;
	pServo->pSerial = pCom;

	ServoPG	*pServoPGDlg;
	CRobotDlg *pRobotDlg;
	CServoMain * pServoMainDlg;


	pServoMainDlg = new CServoMain;
	pServoPGDlg = new ServoPG;
	pRobotDlg = new CRobotDlg;
	
	m_pMainWnd = pServoMainDlg;

	pServoMainDlg->pServoPGDlg = pServoPGDlg;
	pServoMainDlg->pRobotDlg = pRobotDlg;
	pServoMainDlg->pServo = pServo;
	pServoMainDlg->pCs = pCs;
	pServoMainDlg->setup = setup;

	pServoPGDlg->setup = setup;
	pServoPGDlg->pCs = pCs;
	pServoPGDlg->pServo = pServo;
	pServoPGDlg->pServoMainDlg = pServoMainDlg;

	pRobotDlg->setup = setup;
	pRobotDlg->pCs = pCs;
	pRobotDlg->pServo = pServo;

	pServoMainDlg->Create(IDD_SERVOMAIN_DIALOG);
	

	return TRUE;
}
